package cn.wolfcode.wms.page;

import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

@Getter
@Setter
public class PageResult {

    private Integer currentPage;
    private Integer pageSize;
    private Integer totalCount;
    private Integer totalPage;
    private Integer nextPage;
    private Integer prevPage;
    private List<?> list;

    public static PageResult empty(Integer pageSize) {
        return new PageResult(0, Collections.emptyList(), 1, pageSize);
    }

    public PageResult(Integer totalCount, List<?> list, Integer currentPage, Integer pageSize) {
        this.totalCount = totalCount;
        this.list = list;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalPage = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        this.nextPage = this.currentPage + 1 > this.totalPage ? totalPage : this.currentPage + 1;
        this.prevPage = this.currentPage - 1 < 1 ? 1 : this.currentPage - 1;
    }
}
